/**提示与加载工具类 */
export default class Tips {
  constructor() {
    this.isLoading = false
  }
  /**
  * 弹出加载提示
  */
  static loading(title = "加载中") {
    if (Tips.isLoading) {
      return;
    }
    Tips.isLoading = true;
    wx.showLoading({
      title: title,
      mask: true
    });
  }

  /**
   * 加载完毕
   */
  static loaded() {
    if (Tips.isLoading) {
      Tips.isLoading = false;
      wx.hideLoading();
    }
  }

  /**
   * 弹出确认窗口
   */
  static confirm(params) {
    const { text, title, cancelText, confirmText, cancelColor, confirmColor } = params;
    return new Promise((resolve, reject) => {
      wx.showModal({
        title: title || '',
        content: text,
        cancelText: cancelText || 'CANCEL',
        confirmText: confirmText || 'OK',
        cancelColor: cancelColor || '#0099FF',
        confirmColor: confirmColor || '#0099FF',
        success: res => {
          if (res.confirm) {
            resolve();
          } else if (res.cancel) {
            // reject();
          }
        },
        fail: res => {
          reject();
        }
      });
    });
  }

  /**
  * 错误警告框
  */
  static alert(title) {
    wx.showToast({
      title: title,
      icon: "none",
      mask: true,
      duration: 2000
    });
  }
  /**
   * 提示框
   */
  static toast(params) {
    const { title, icon } = params
    setTimeout(() => {
      wx.showToast({
        title: title || '',
        icon: icon || 'success',
        mask: true,
        duration: 500
      });
    }, 300);
  }


}
Tips.isLoading = false